New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

webext-detect

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webext-detect

Detects where the current browser extension code is being run. Compatible with Firefox, Chrome and derivates.

  • 5.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
increased by21.77%
Maintainers
0
Weekly downloads
 
Created
Source

webext-detect

Detects where the current browser extension code is being run.

This package was recently renamed from webext-detect-page to webext-detect

Install

You can download the standalone bundle and include it in your manifest.json.

Or use npm:

npm install webext-detect

Usage

import {isBackground, isContentScript} from 'webext-detect';

if (isBackground()) {
	// Run background code, e.g.
	browser.runtime.onMessage.addListener(console.log);
} else if (isContentScript()) {
	// Run content script code, e.g.
	browser.runtime.sendMessage('wow!');
}

API

The functions are only ever evaluated once. This protects from future "invalidated context" errors. Read the note about testing if you're running this code in a tester.

To see all the available functions, check the index.d.ts file.

There are also a few helper functions based on the useragent string to loosely detect the current browser: isChrome(), isFirefox(), isSafari(), isMobileSafari(). They are not intended to detect forks, but just the main engines.

Testing

The calls are automatically cached so, if you're using this in a test environment, import and call this function first to ensure that the environment is "detected" every time:

import {disableWebextDetectPageCache} from 'webext-detect';
disableWebextDetectPageCache();

License

MIT © Federico Brigante

Keywords

FAQs

Package last updated on 11 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc